import 'package:flutter/material.dart';

/// [BuildContext]方法扩展
extension BuildContextExt on BuildContext {
  /// 获取当前组件的 RenderBox
  RenderBox? renderBox() {
    return findRenderObject() is RenderBox
        ? (findRenderObject() as RenderBox)
        : null;
  }

  /// 键盘是否可见
  bool get keyboardVisible => MediaQuery.of(this).viewInsets.bottom > 70;

  /// 当前组件相对位置在整个屏幕的位置
  Offset? position({Offset offset = Offset.zero}) {
    try {
      return renderBox()?.localToGlobal(offset);
    } catch (e) {
      return null;
    }
  }
}
